package com.gxa.controller.HospitalController;

import com.gxa.entity.ComboItems;
import com.gxa.service.ComboService;
import com.gxa.service.ItemsService;
import com.gxa.service.TypesService;
import com.gxa.utils.ImageUpload;
import com.gxa.utils.R;
import com.gxa.vo.*;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


@Api(tags="体检套餐管理模块相关接口")
@RestController
public class ComboController {

    @Autowired
    private ComboService comboService;

    @Autowired
    private ItemsService itemsService;

    @Autowired
    private TypesService typesService;

    @ApiOperation(value="体检套餐图片上传接口",notes="方法的详细描述",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })

    @PostMapping("/ComboPic")

    public R ComboPic(@ModelAttribute @Validated ComboVoPic comboVo) throws IOException {
        MultipartFile pic = comboVo.getUrl();//获取传过来的图片文件
        System.out.println("##############################################");
        String url = ImageUpload.upload(pic);//传过来的文件放在工具类里面处理
        System.out.println(url);

        return R.ok().put("data",url);
    }

    @ApiOperation(value="体检套餐无参查询接口",notes="",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:sel")
    @PostMapping("/doc/QueryCombosAll")
    public R QueryCombosAll(){
        List<ComboVo1> comboVos = this.comboService.queryComboAll();
        for (int i = 0; i < comboVos.size(); i++) {
            String comboId = comboVos.get(i).getComboId();
            List<String> items = this.comboService.queryItemsName(comboId);
            comboVos.get(i).setItems(items);
        }

        System.out.println(comboVos);

        return R.ok().put("data",comboVos);

    }

    @ApiOperation(value="体检套餐套餐类型下拉框查询接口",notes="",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:sel")
    @PostMapping("/doc/QueryCombosTypeName")
    public R QueryCombosTypeName(){
        List<String> list = this.comboService.queryComboTypeName();
        System.out.println(list);
        return R.ok().put("data",list);

    }

    @ApiOperation(value="体检套餐查询接口",notes="体检套餐，根据套餐名称搜索",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:sel")
    @PostMapping("/doc/QueryCombos")
    public R QueryCombos(@ApiParam(name="套餐名",value = "根据套餐名称搜索",required = true)@RequestBody ComboVo1 comboVo1){
        /**
         * List<ComboVo1> comboVos = this.comboService.queryComboAll();
         *         for (int i = 0; i < comboVos.size(); i++) {
         *             String comboId = comboVos.get(i).getComboId();
         *             List<String> items = this.comboService.queryItemsName(comboId);
         *             comboVos.get(i).setItems(items);
         *         }
         */
        List<ComboVo1> comboVo1s = this.comboService.queryComboByName(comboVo1);
        for (int i = 0; i < comboVo1s.size(); i++) {
             String comboId = comboVo1s.get(i).getComboId();
             List<String> items = this.comboService.queryItemsName(comboId);
             comboVo1s.get(i).setItems(items);
        }
        System.out.println(comboVo1s);
        return R.ok().put("data",comboVo1s);

    }
    @ApiOperation(value="体检套餐修改前查询接口",notes="体检套餐修改前查询接口",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:sel")
    @PostMapping("/doc/PreQueryCombos")
    public R PreQueryCombos(@ApiParam(name="套餐名",value = "根据套餐名称搜索",required = true)@RequestBody ComboVo1 comboVo1){
//        List<ComboVo1> comboVo1s = new ArrayList<>();
//        ComboItems comboItems = new ComboItems();
//
//        for (int i = 0; i < comboVo1.getItems().size(); i++) {
//            String itemsId = this.comboService.queryItemsId(comboVo1.getItems().get(i));
//            comboItems.setItemsId(itemsId);
//            comboItems.setComboId(comboVo1.getComboId());
//            ComboVo1 combos = this.comboService.PreQueryCombos(comboItems);
//            if (comboVo1s != null && comboVo1s.size() > 0){
//                comboVo1s.set(i,combos);
//                System.out.println(comboItems);
//                System.out.println(comboVo1s);
//            }
//        }
        ComboVo1 comboVo1s = this.comboService.queryComboById(comboVo1);

        String comboId = comboVo1s.getComboId();
        List<String> items = this.comboService.queryItemsName(comboId);
        comboVo1s.setItems(items);

        return R.ok().put("data",comboVo1s);

    }

    @ApiOperation(value="体检套餐修改接口",notes="体检套餐",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:update")
    @PutMapping("/doc/EditCombos")
    public R EditCombos(@ApiParam(name="修改后的数据",value = "根据修改后的数据修改",required = true)@RequestBody ComboVo1 comboVo1){
        this.comboService.EditCombos(comboVo1);
        ComboItems comboItems = new ComboItems();
        for (int i = 0; i < comboVo1.getItems().size(); i++) {
            String itemsId = this.comboService.queryItemsId(comboVo1.getItems().get(i));
            comboItems.setItemsId(itemsId);
            comboItems.setComboId(comboVo1.getComboId());
            int id = this.comboService.queryCIId(comboItems);
            comboItems.setId(id);
            this.comboService.EditCombosItems(comboItems);
            System.out.println(comboItems);
        }
        System.out.println(comboVo1);
        return R.ok();

    }

    @ApiOperation(value="体检套餐查询院区下拉列表接口",notes="体检套餐、查询套餐类型、院区、项目、价格列表",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:sel")
    @GetMapping("/doc/PreAddCombosQueryCampus")
    public R PreAddCombosQueryCampus(){
        List<String> list = this.comboService.PreAddCombosQueryCampus();
        System.out.println(list);
        return R.ok().put("data",list);

    }

    @ApiOperation(value="体检套餐查询套餐项目下拉列表接口",notes="体检套餐、查询套餐类型、院区、项目、价格列表",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:sel")
    @GetMapping("/doc/PreAddCombosQueryItems")
    public R PreAddCombosQueryItems(){
        List<String> list = this.comboService.PreAddCombosQueryItems();
        System.out.println(list);
        return R.ok().put("data",list);

    }

    @ApiOperation(value="体检套餐添加接口",notes="体检套餐、根据套餐参数添加",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:add")
    @PostMapping("/doc/addCombos")
    public R addCombos(@ApiParam(name="套餐",value = "套餐参数",required = true)@RequestBody ComboVo1 comboVo1){
        this.comboService.addCombos(comboVo1);

        ComboItems comboItems = new ComboItems();
        for (int i = 0; i < comboVo1.getItems().size(); i++) {
            String itemsId = this.comboService.queryItemsId(comboVo1.getItems().get(i));
            comboItems.setItemsId(itemsId);
            comboItems.setComboId(comboVo1.getComboId());
            this.comboService.addCombosItems(comboItems);
            System.out.println(comboItems);
        }

        System.out.println(comboVo1);
        return R.ok();

    }

    @ApiOperation(value="体检套餐删除接口",notes="体检套餐、根据套餐参数删除",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:del")
    @DeleteMapping("/doc/DelCombos")
    public R DelCombos(@ApiParam(name="套餐",value = "根据套餐参数删除",required = true)@RequestBody ComboVo1 comboVo1){
        this.comboService.DelCombos(comboVo1);
        ComboItems comboItems = new ComboItems();
        for (int i = 0; i < comboVo1.getItems().size(); i++) {
            String itemsId = this.comboService.queryItemsId(comboVo1.getItems().get(i));
            comboItems.setItemsId(itemsId);
            comboItems.setComboId(comboVo1.getComboId());
            int id = this.comboService.queryCIId(comboItems);
            comboItems.setId(id);
            this.comboService.DelCombosItems(comboItems);
            System.out.println(comboItems);
        }
        System.out.println(comboVo1);
        return R.ok();

    }





    //体检项目

    @ApiOperation(value="体检项目无参查询接口",notes="体检项目，项目ID 项目名称 项目价格(元) 所属套餐 项目介绍 注意事项 项目状态",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:sel")
    @PostMapping("/doc/QueryItemsALL")
    public R QueryItemsALL(){
        List<ItemsVo> itemsVos = this.itemsService.QueryItemsALL();

        System.out.println(itemsVos);
        return R.ok().put("data",itemsVos);

    }

    @ApiOperation(value="体检项目查询接口",notes="体检项目，项目ID 项目名称 项目价格(元) 所属套餐 项目介绍 注意事项 项目状态",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:sel")
    @PostMapping("/doc/QueryItems")
    public R QueryItems(@ApiParam(name="套餐名",value = "根据套餐名称搜索",required = true)@RequestBody ItemsVo itemsVo){
        List<ItemsVo> itemsVos = this.itemsService.QueryItems(itemsVo.getCombo());
        System.out.println(itemsVos);
        return R.ok().put("data",itemsVos);

    }

    @ApiOperation(value="体检项目查询所属套餐下拉框接口",notes="体检项目修改前查询接口",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:sel")
    @PostMapping("/doc/PreQueryComboName")
    public R PreQueryComboName(){
        List<String> combo = this.itemsService.PreQueryComboName();
        System.out.println(combo);
        return R.ok().put("data",combo);

    }

    @ApiOperation(value="体检项目修改前查询接口",notes="体检项目修改前查询接口",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:sel")
    @PostMapping("/doc/PreQueryItems")
    public R PreQueryItems(@ApiParam(name="项目名",value = "根据项目名称搜索",required = true)@RequestBody ItemsVo itemsVo){
        ItemsVo1 itemsVo1 = new ItemsVo1();
        List<String> combo = this.itemsService.QueryComboNameByItemsId(itemsVo.getItemsId());

        ItemsVo items = this.itemsService.PreQueryItems(itemsVo);
        itemsVo1.setAttention(items.getAttention());
        itemsVo1.setItemsId(items.getItemsId());
        itemsVo1.setMoney(items.getMoney());
        itemsVo1.setName(items.getName());
        itemsVo1.setStatus(items.getStatus());
        itemsVo1.setText(items.getText());

        itemsVo1.setCombo(combo);

        System.out.println(itemsVo1);
        return R.ok().put("data",itemsVo);

    }

    @ApiOperation(value="体检项目修改接口",notes="体检项目",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:update")
    @PutMapping("/doc/EditItems")
    public R EditItems(@ApiParam(name="修改后的数据",value = "根据修改后的数据修改",required = true)@RequestBody ItemsVo1 itemsVo1){
        System.out.println(itemsVo1);
        this.itemsService.EditItems(itemsVo1);
        ComboItems comboItems = new ComboItems();
        comboItems.setItemsId(itemsVo1.getItemsId());
        for (int i = 0; i < itemsVo1.getCombo().size(); i++) {
            comboItems.setComboId(itemsVo1.getCombo().get(i));
            int id = this.comboService.queryCIId(comboItems);
            comboItems.setId(id);
            this.itemsService.EditComboItems(comboItems);
        }
        return R.ok();

    }

    @ApiOperation(value="体检项目添加前查询下拉框接口",notes="体检项目，查询套餐名",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:sel")
    @GetMapping("/doc/PreAddItems")
    public R PreAddItems(){
        List<String> combo = this.itemsService.PreQueryComboName();
        System.out.println(combo);
        return R.ok().put("data",combo);

    }

    @ApiOperation(value="体检项目添加接口",notes="体检套餐、根据套餐参数添加",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:add")
    @PostMapping("/doc/addItems")
    public R addItems(@ApiParam(name="套餐",value = "套餐参数",required = true)@RequestBody ItemsVo1 itemsVo1){
        this.itemsService.addItems(itemsVo1);
        ComboItems comboItems = new ComboItems();
        comboItems.setItemsId(itemsVo1.getItemsId());
        for (int i = 0; i < itemsVo1.getCombo().size(); i++) {
            comboItems.setComboId(this.itemsService.QueryComboId(itemsVo1.getCombo().get(i)));
            this.comboService.addCombosItems(comboItems);
            System.out.println(comboItems);
        }
        System.out.println(itemsVo1);
        return R.ok();

    }

    @ApiOperation(value="体检项目删除接口",notes="体检项目、根据体检项目参数删除",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:del")
    @DeleteMapping("/doc/DelItems")
    public R DelItems(@ApiParam(name="套餐",value = "根据套餐参数删除",required = true)@RequestBody ItemsVo1 itemsVo1){
        this.itemsService.DelItems(itemsVo1);
        ComboItems comboItems = new ComboItems();
        comboItems.setItemsId(itemsVo1.getItemsId());
        for (int i = 0; i < itemsVo1.getCombo().size(); i++) {
            comboItems.setComboId(this.itemsService.QueryComboId(itemsVo1.getCombo().get(i)));
            comboItems.setId(this.comboService.queryCIId(comboItems));
            this.itemsService.DelCombosItems(comboItems);
            System.out.println(comboItems);
        }
        System.out.println(itemsVo1);
        return R.ok();

    }




    //套餐类型
    @ApiOperation(value="套餐类型无参查询接口",notes="类型名称 套餐数量 包含套餐 状态",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回查询详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 400, message = "请求错误"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("hos:sel")
    @GetMapping("/doc/QueryTypes")
    public R QueryTypes(){
        List<TypesVo1> typesVo1s = this.comboService.QueryTypes();
        System.out.println(typesVo1s);
        System.out.println("############################################################");
        for (int i = 0; i < typesVo1s.size(); i++) {

            List<String> comboName = this.typesService.queryComboNameByTypeName(typesVo1s.get(i).getTypeName());
            typesVo1s.get(i).setNum(comboName.size());
            typesVo1s.get(i).setCombo(comboName);
        }
        System.out.println(typesVo1s);
        return R.ok().put("data",typesVo1s);

    }

}
